package com.deng.maintenance.item_weight.view
{
	import com.deng.maintenance.model.MaintenanceModelLocator;
	import com.deng.maintenance.item_weight.vo.ItemWeightVo;
	
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	
	import mx.controls.TextInput;
	import mx.events.FlexEvent;
	import mx.utils.StringUtil;

	public class ItemPointTextInput extends TextInput
	{
		private var txt:int;
		private var pvo:ItemWeightVo;
		public function ItemPointTextInput()
		{
			this.restrict = "0-9";
			this.maxChars = 5;
			txt = new Number(this.text);
//			this.addEventListener(MouseEvent.CLICK,insideTxt);
			this.addEventListener(FocusEvent.FOCUS_IN,insideTxt);
			
			this.addEventListener(FocusEvent.FOCUS_OUT,updateData);
			
			this.addEventListener(FlexEvent.SHOW,showHandler);
			super();
		}
		private function showHandler(event:FlexEvent):void{
			pvo = this.data as ItemWeightVo;
			this.text = pvo.point+"";
		}
		private function insideTxt(event:Event):void{
			pvo = this.data as ItemWeightVo;
			txt = new Number(this.text);
		}
		public function updateData(event:FocusEvent):void{
			if(new Number(this.text) > 100){
				this.text = txt+"";
			}else{
				pvo.point = StringUtil.trim(this.text);
				pvo.update_mark = 1;
				
				for(var i:int = 0;i<MaintenanceModelLocator.getInstance().itemWeightArr.length;i++){
					var vo:ItemWeightVo = MaintenanceModelLocator.getInstance().itemWeightArr.getItemAt(i) as ItemWeightVo;
					if(vo.wid == pvo.wid){
						MaintenanceModelLocator.getInstance().itemWeightArr.setItemAt(pvo,i);
						return;
					}
				}
				
			}
			
		}
	}
}